package com.example.demooptimizeif.service.impl;

import com.example.demooptimizeif.entity.User;
import com.example.demooptimizeif.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.IntFunction;

/**
 * @version 1.0.0
 * @className: UserServiceImpl
 * @description:
 * @author: zhangjunfa
 * @date: 2023/9/2 12:19
 */

@Service
public class UserServiceImpl implements UserService {
    private final static Logger log = LoggerFactory.getLogger(UserServiceImpl.class);

    @Override
    public User getUser(Integer type) {
        if (type == 1) {
            return new User(1, "用户", 1);
        } else if (type == 2) {
            return new User(2, "学生", 2);
        } else if (type == 3) {
            return new User(3, "程序猿", 3);
        } else {
            return new User(99, "老师", 99);
        }
    }

    @Override
    public void getUsers(Integer type) {
        Map<Integer, Function<Integer, Integer>> functionMap = new HashMap<>();
        // 初始化
        functionMap.put(1, (Integer value) -> doSomethings1(value));
        functionMap.put(2, (Integer value) -> doSomethings2(value));
        functionMap.put(3, (Integer value) -> doSomethings3(value));
        functionMap.put(4, (Integer value) -> doSomethings4(value));

        functionMap.get(type).apply(type);
    }

    private Integer doSomethings1(Integer type) {
        log.info("我是一个用户，我的类型是:{},我搬砖", type);
        return type;
    }

    private Integer doSomethings2(Integer type) {
        log.info("我是一个学生，我的类型是:{},我会努力的学习", type);
        return type;
    }

    private Integer doSomethings3(Integer type) {
        log.info("我是一个程序猿，我的类型是:{},我只会写BUG", type);
        return type;
    }

    private Integer doSomethings4(Integer type) {
        log.info("我是一个老师，我的类型是:{},我辛勤的培育祖国的花朵。", type);
        return type;
    }
}
